package com.hayrullah.cinema.Dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.hayrullah.cinema.Util.HibernateUtil;
import com.hayrullah.cinema.entity.Ticket;

public class TicketDao extends AbstractDao<Ticket> {

	@Override
	public Ticket findById(Long id) {
		Ticket ticket = null;
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			ticket = (Ticket) session.get(Ticket.class, id);
			session.getTransaction().commit();
		} catch (HibernateException exception) {
			exception.printStackTrace();
		}

		return ticket;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Ticket> findAll() {
		List<Ticket> tickets = null;
		try {
			Session session = HibernateUtil.getSessionFactory()
					.getCurrentSession();
			session.beginTransaction();
			tickets = (List<Ticket>) session.createCriteria(Ticket.class)
					.list();
			session.getTransaction().commit();
		} catch (HibernateException e) {

		}
		return tickets;
	}

	
}
